<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no">

  <title>我喜欢的音乐列表</title>

  <link rel="shortcut icon" href="#" />
  <link href="css/bootstrap.min.css" rel="stylesheet">
  <script src="js/jquery-3.1.1.min.js"></script>

  <style>
    body {
      margin: 0;
      padding: 0;
      min-height: 100vh;
      background: url("/images/img-new-cd.jpg") no-repeat center center fixed;
      background-size: cover;
      font-family: "Segoe UI", "Microsoft YaHei", sans-serif;
      color: #fff;
    }

    .container {
      background-color: rgba(0, 0, 0, 0.6);
      padding: 40px;
      border-radius: 20px;
      margin-top: 40px;
      box-shadow: 0 8px 32px rgba(0, 0, 0, 0.6);
    }

    h3 {
      text-align: center;
      margin-bottom: 30px;
      font-size: 26px;
      font-weight: bold;
      background: linear-gradient(90deg, #8a79ff, #a57aff);
      -webkit-background-clip: text;
      -webkit-text-fill-color: transparent;
    }

    .form-inline label {
      color: #ddd;
      margin-right: 10px;
    }

    .form-control {
      background-color: rgba(255, 255, 255, 0.07);
      border: none;
      color: #fff;
      border-radius: 8px;
    }

    .form-control::placeholder {
      color: #aaa;
    }

    .btn-default, .btn-primary {
      border-radius: 10px;
      font-weight: bold;
    }

    .btn-primary {
      background: linear-gradient(135deg, #6a5acd, #8e7dff);
      border: none;
    }

    .btn-primary:hover {
      background: linear-gradient(135deg, #9b87ff, #bfa7ff);
      transform: scale(1.02);
      box-shadow: 0 0 10px rgba(138, 115, 255, 0.4);
    }

    table {
      background-color: rgba(255, 255, 255, 0.05);
      border-radius: 10px;
      overflow: hidden;
    }

    th, td {
      text-align: center;
      vertical-align: middle;
      color: #f0f0f0;
    }

    th {
      background-color: rgba(138, 115, 255, 0.3);
    }

    audio {
      width: 180px;
    }
  </style>

  <script>
    $(function() {
      load();

      $("#submit1").click(function() {
        var name = $("#exampleInputName2").val();
        load(name);
      });
    });

    function load(musicName) {
      $.ajax({
        url: "/lovemusic/findlovemusic",
        data: {"musicName": musicName},
        type: "GET",
        dataType: "json",
        success: function(obj) {
          var data = obj.data;
          var s = '';
          for (var i = 0; i < data.length; i++) {
            var musicUrl = data[i].url + ".mp3";
            s += '<tr>';
            s += '<td>' + data[i].title + '</td>';
            s += '<td>' + data[i].singer + '</td>';
            s += '<td><audio src="' + musicUrl + '" controls preload="none" loop></audio></td>';
            s += '<td><button class="btn btn-primary" onclick="deleteInfo(' + data[i].id + ')">移除</button></td>';
            s += '</tr>';
          }
          $("#info").html(s);
        }
      });
    }

    function deleteInfo(id) {
      $.ajax({
        url: "/lovemusic/deleteLikeMusic",
        type: "POST",
        data: {"id": id},
        dataType: "json",
        success: function(val) {
          if (val.data == true) {
            alert("删除成功！,重新加载当前页面！");
            window.location.href = "list.html";
          } else {
            alert("删除失败！");
          }
        }
      });
    }
  </script>
</head>
<body>
<div class="container">
  <h3>🎵 我喜欢的音乐列表</h3>
  <div class="d-flex justify-content-between mb-3">
    <form class="form-inline">
      <div class="form-group">
        <label for="exampleInputName2">歌曲名</label>
        <input name="name" type="text" class="form-control" id="exampleInputName2" placeholder="请输入歌名">
      </div>
      <button id="submit1" type="button" class="btn btn-default ml-2">查询</button>
    </form>
    <a class="btn btn-primary" href="list.html">回到首页</a>
  </div>
  <table class="table table-bordered table-hover">
    <thead>
      <tr>
        <th>歌名</th>
        <th>歌手</th>
        <th>歌曲</th>
        <th>操作</th>
      </tr>
    </thead>
    <tbody id="info"></tbody>
  </table>
</div>

<div style="width: 180px; height: 140px; position:absolute; bottom:10px; right:10px">
  <script type="text/javascript" src="player/sewise.player.min.js"></script>
  <script type="text/javascript">
    SewisePlayer.setup({
      server: "vod",
      type: "mp3",
      videourl: "http://jackzhang1204.github.io/materials/where_did_time_go.mp3",
      skin: "vodWhite",
      autostart: "false",
    });
  </script>
</div>
</body>
</html>
